/* 强制让三个操作按钮竖直排列并占满宽度（覆盖可能的全局样式） */
.vertical-actions {
  display: flex !important;
  flex-direction: column !important;
  gap: 12px !important;
  align-items: stretch !important;
  width: 100%;
}

/* 按钮占满容器宽度并居中内容 */
.vertical-actions .btn,
.vertical-actions .btn.full,
.vertical-actions .full {
  width: 100% !important;
  box-sizing: border-box;
  padding: 10px 14px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

/* 小屏适配，缩小间距 */
@media (max-width: 520px) {
  .vertical-actions { gap: 8px !important; }
  .vertical-actions .btn { padding: 10px 12px; }
}

/* 检测页面专用样式 */

/* 页面头部 */
.page-header-detect {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 24px 0;
  gap: 24px;
  flex-wrap: wrap;
  animation: fadeInUp 0.6s ease-out;
}

/* 检测统计卡片行 */
.detection-stats-row {
  display: flex;
  gap: 16px;
}

.stat-card {
  background: white;
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 140px;
  transition: all var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.stat-icon {
  font-size: 32px;
  line-height: 1;
}

.stat-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.stat-label {
  font-size: 12px;
  color: #4b5563;
  font-weight: 600;
}

/* 进度条 */
.progress-container {
  position: relative;
  margin-bottom: 24px;
  animation: fadeInUp 0.6s ease-out 0.1s both;
}

.progress-bar {
  width: 100%;
  height: 12px;
  background: var(--bg);
  border-radius: var(--radius-full);
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
  position: relative;
  overflow: hidden;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* 检测布局 */
.detect-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  align-items: start;
}

/* 左侧控制面板 - 使用flexbox让内容自然分布 */
.control-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 让输入源模块自动增长，把操作模块推到底部 */
.control-panel .control-card:nth-child(2) {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

/* 确保输入源卡片内容不会过度拉伸 */
.control-panel .control-card:nth-child(2) .control-content {
  margin-top: auto;
}

.control-card {
  animation: fadeInLeft 0.6s ease-out;
}

.control-card:nth-child(2) {
  animation-delay: 0.1s;
}

.control-card:nth-child(3) {
  animation-delay: 0.2s;
}

.control-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--bg);
}

.control-icon {
  font-size: 24px;
  line-height: 1;
}

.control-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.control-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.model-select {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #e5e7eb;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition-fast);
  background: white;
  cursor: pointer;
}

.model-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15,99,255,0.1);
}

.input-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* 主检测区域 */
.detection-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100%;
}

/* 确保实时检测视图与模型选择顶部对齐 */
.detection-viewer {
  animation: fadeInRight 0.6s ease-out 0.2s both;
  height: 100%;
  display: flex;
  flex-direction: column;
  margin-top: 0; /* 确保与左侧第一个卡片对齐 */
}

.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--bg);
}

.viewer-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.viewer-icon {
  font-size: 22px;
  line-height: 1;
}

.viewer-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  border-radius: var(--radius-md);
  font-size: 18px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--primary);
  transform: scale(1.1);
}

.viewer-content {
  min-height: 300px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.image-display {
  position: relative;
  width: 100%;
  min-height: 300px;
  background: #f9fafb;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-display img {
  max-width: 100%;
  max-height: 400px;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-md);
}

.bbox {
  pointer-events: none;
}

@keyframes bboxPulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

.image-info-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius-md);
  margin-top: 16px;
}

.image-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text);
}

.file-icon {
  font-size: 20px;
}

.image-actions {
  display: flex;
  gap: 8px;
}

.empty-viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  text-align: center;
  padding: 40px;
}

.empty-icon {
  font-size: 80px;
  margin-bottom: 20px;
  opacity: 0.5;
  animation: float 3s ease-in-out infinite;
}

.empty-viewer h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

.empty-viewer p {
  font-size: 15px;
  color: var(--text-secondary);
}

/* 摄像头预览 */
.camera-preview {
  animation: fadeInUp 0.4s ease-out;
}

.camera-container {
  display: flex;
  gap: 20px;
  align-items: center;
}

.camera-video {
  width: 480px;
  height: 360px;
  border-radius: var(--radius-lg);
  background: #000;
  object-fit: cover;
  box-shadow: var(--shadow-md);
}

.camera-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 结果卡片 */
.results-card {
  animation: fadeInUp 0.6s ease-out 0.3s both;
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-bottom: 0; /* 确保底部对齐 */
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--bg);
}

.results-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.results-icon {
  font-size: 22px;
}

.results-badge {
  padding: 6px 16px;
  background: var(--info-light);
  color: var(--info);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 700;
}

.results-table-container {
  overflow-x: auto;
  border-radius: var(--radius-md);
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

.results-table th {
  background: var(--bg);
  padding: 14px 16px;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.results-table td {
  padding: 16px;
  border-bottom: 1px solid var(--bg);
}

.result-row {
  transition: background var(--transition-fast);
}

.result-row:hover {
  background: var(--surface-hover);
}

.row-index {
  font-weight: 700;
  color: var(--text-secondary);
  width: 60px;
}

.row-class {
  min-width: 120px;
}

.class-badge {
  display: inline-block;
  padding: 4px 12px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
}

.row-confidence {
  min-width: 200px;
}

.confidence-bar-container {
  position: relative;
  width: 100%;
  height: 24px;
  background: var(--bg);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.confidence-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--warning));
  border-radius: var(--radius-full);
  transition: width 0.6s ease;
}

.confidence-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}

.row-bbox {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 180px;
}

.row-risk {
  text-align: center;
  min-width: 80px;
}

.risk-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
}

.risk-high {
  background: var(--danger-light);
  color: var(--danger);
}

.risk-medium {
  background: var(--warning-light);
  color: var(--warning);
}

.risk-low {
  background: var(--success-light);
  color: var(--success);
}

.empty-cell {
  padding: 0 !important;
}

.empty-table {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-table span {
  font-size: 48px;
  display: block;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-table p {
  font-size: 15px;
  margin: 0;
}

/* 模态框 */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-content {
  background: white;
  border-radius: var(--radius-xl);
  max-width: 900px;
  max-height: 90vh;
  width: 100%;
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  animation: modalSlideUp 0.4s ease-out;
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(40px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 28px;
  border-bottom: 2px solid var(--bg);
}

.modal-header h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.btn-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  border-radius: var(--radius-md);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-close:hover {
  background: var(--danger);
  color: white;
  transform: rotate(90deg);
}

.modal-body {
  padding: 28px;
  overflow-y: auto;
  max-height: calc(90vh - 140px);
}

.modal-image-wrap {
  position: relative;
  width: 100%;
  max-height: 600px;
  background: #f9fafb;
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.modal-image-wrap img {
  max-width: 100%;
  max-height: 600px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.modal-tags {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius-md);
}

.modal-tags strong {
  color: var(--text);
  font-weight: 600;
}

.tag {
  padding: 4px 12px;
  background: var(--primary);
  color: white;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
}

.no-tags {
  color: var(--text-secondary);
  font-style: italic;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .detect-layout {
    grid-template-columns: 280px 1fr;
  }

  .control-panel {
    position: static;
  }

  .input-buttons {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 968px) {
  .page-header-detect {
    flex-direction: column;
    align-items: flex-start;
  }

  .detection-stats-row {
    width: 100%;
    overflow-x: auto;
  }

  .detect-layout {
    grid-template-columns: 1fr;
  }

  .camera-container {
    flex-direction: column;
  }

  .camera-video {
    width: 100%;
    height: auto;
    aspect-ratio: 4/3;
  }

  .camera-controls {
    width: 100%;
  }

  .camera-controls .btn {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .stat-card {
    flex: 1;
    min-width: 0;
  }

  .results-table-container {
    font-size: 12px;
  }

  .results-table th,
  .results-table td {
    padding: 10px 8px;
  }

  .confidence-bar-container {
    min-width: 100px;
  }
}

/* 动画关键帧 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes float {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}